﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD4Fun.Observer;

namespace DDD4Fun.Ducks
{
    public class DuckSimulator
    {

        public static void Go()
        {
            DuckSimulator ss = new DuckSimulator();

            AbstractDuckFactory basicDuckFactory = new BasicDuckFactory();
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("basicduck simulator go");
            ss.simulator(basicDuckFactory);
            Console.WriteLine("-----------------------------------------");

            AbstractDuckFactory counterDuckFactory = new CounterDuckFactory();
            Console.WriteLine("-----------------------------------------");
            Console.WriteLine("counterduck simulator go");
            ss.simulator(counterDuckFactory);
            Console.WriteLine("-----------------------------------------");
        }

        void simulator(AbstractDuckFactory duckFactory)
        {
            IQuackable mallardDuck = duckFactory.CreateMallardDuck() ;
            IQuackable redheadDuck = duckFactory.CreateRedheadDuck();
            IQuackable rubberDuck = duckFactory.CreateRubberDuck();
            IQuackable duckCall = duckFactory.CreateDuckCall();
            IQuackable goose = new GooseAdapter(new Goose());

        
            Console.WriteLine("init duck quack counter:" + QuackCounter.getQuacks());

            //simulator(mallardDuck);
            //Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());

            //simulator(redheadDuck);
            //Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());

            //simulator(rubberDuck);
            //Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());

            //simulator(duckCall);
            //Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());

            //simulator(goose);
            //Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());

            Flock flock = new Flock();
            flock.Add(mallardDuck);
            flock.Add(rubberDuck);
            flock.Add(duckCall);
            flock.Add(redheadDuck);
            flock.Add(goose);

         //   simulator(flock);
            Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());

            Flock mallardFlock = new Flock();
            IQuackable mallardDuck1 = duckFactory.CreateMallardDuck();
            IQuackable mallardDuck2 = duckFactory.CreateMallardDuck();
            IQuackable mallardDuck3 = duckFactory.CreateMallardDuck();
            IQuackable mallardDuck4 = duckFactory.CreateMallardDuck();
            mallardFlock.Add(mallardDuck1);
            mallardFlock.Add(mallardDuck2);
            mallardFlock.Add(mallardDuck3);
            mallardFlock.Add(mallardDuck4);
            flock.Add(mallardFlock);

            IObserver ob = new QuackLogist();
            flock.Register(ob);

            simulator(flock);
            Console.WriteLine("duck quack counter:" + QuackCounter.getQuacks());
        }

        void simulator(IQuackable duck)
        {
            duck.Quack();
        }
    }
}
